{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import k3d\n",
    "import numpy as np\n",
    "\n",
    "N = 100\n",
    "\n",
    "theta = np.linspace(0, 2.0 * np.pi, N)\n",
    "phi = np.linspace(0, 2.0 * np.pi, N)\n",
    "theta, phi = np.meshgrid(theta, phi)\n",
    "\n",
    "c, a = 2, 1\n",
    "x = (c + a * np.cos(theta)) * np.cos(phi)\n",
    "y = (c + a * np.cos(theta)) * np.sin(phi)\n",
    "z = a * np.sin(theta)\n",
    "\n",
    "vertices = np.dstack([x, y, z]).astype(np.float32)\n",
    "indices = (np.stack([\n",
    "    np.arange(N*N - N - 1) + 0, np.arange(N*N - N - 1) + N, np.arange(N*N - N - 1) + N + 1,\n",
    "    np.arange(N*N - N - 1) + 0, np.arange(N*N - N - 1) + N + 1, np.arange(N*N - N - 1) + 1\n",
    "]).T).astype(np.uint32)\n",
    "\n",
    "plot = k3d.plot()\n",
    "\n",
    "points = k3d.points(vertices, point_size=0.05, shader='3d', color=0)\n",
    "\n",
    "\n",
    "mesh = k3d.mesh(vertices, indices, flat_shading=False, \n",
    "                 shader='mesh',\n",
    "                 attribute=phi, \n",
    "                 color_map=k3d.matplotlib_color_maps.twilight,\n",
    "                 color=0x00ff00)\n",
    "\n",
    "wire = k3d.lines(vertices, indices, flat_shading=False, \n",
    "                 shader='mesh', width=0.003,\n",
    "                 indices_type='segment',\n",
    "                 color=0)\n",
    "\n",
    "\n",
    "plot += mesh\n",
    "plot += wire\n",
    "plot += points\n",
    "\n",
    "plot.display()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot.camera_reset(0.8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mesh.shininess = 500"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mesh.attribute = []\n",
    "plot.colorbar_object_id = -1\n",
    "mesh.colors = np.random.randint(0, 0xFFFFFF, N * N).astype(np.uint32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
